import { useEffect, useState } from 'react';

export default function(sentMeg: Function) {
  const [showDragMark, setShowDragMark] = useState(false);
  /**
   *
   * drag
   *
   */
  useEffect(() => {
    /* 拖动目标元素时触发drag事件 */
    document.addEventListener(
      'drag',
      function(event) {
        sentMeg({
          data: { y: event.clientY - 60, x: event.clientX - 350 },
          code: 'drag',
        });
      },
      false,
    );
    document.addEventListener(
      'dragstart',
      function(event) {
        setShowDragMark(true);
      },
      false,
    );
    document.addEventListener(
      'dragend',
      function(event) {
        setShowDragMark(false);
      },
      false,
    );
  }, []);

  return showDragMark;
}
